﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Sinacor.OMM.HealthMonitor.Entity.Receiver;

namespace Sinacor.OMM.HealthMonitor.Collector.SharedHealthDataMemoryStorage.Receiver
{
    [Serializable]
    public class ReceiverShdms : IDisposable
    {
        private static ReceiverShdms _receiverShmds;
        private static Mutex mtx = new Mutex();

        private ReceiverShdms()
        {

        }

        public static ReceiverShdms GetSharedStorage()
        {
            mtx.WaitOne();
            if (_receiverShmds == null)
            {
                _receiverShmds = new ReceiverShdms();
            }
            mtx.ReleaseMutex();

            return _receiverShmds;
        }

        private ReceiverData _receiverData;
        public ReceiverData ReceiverDataInfo
        {
            get
            {
                if (_receiverData == null)
                    _receiverData = new ReceiverData();

                return _receiverData;
            }
        }

        #region IDisposable Members

        public void Dispose()
        {
            _receiverShmds = null;
            mtx.Close();
            _receiverData = null;
        }

        #endregion
    }
}
